/*
 * @lc app=leetcode.cn id=290 lang=typescript
 *
 * [290] 单词规律
 */

// @lc code=start
function wordPattern(pattern: string, s: string): boolean {
    const map = new Map();
    const arr = s.split(' ');
    if (arr.length !== pattern.length) {
        return false;
    }
    const set = new Set();
    for (let i = 0; i < pattern.length; i++) {
        const v = map.get(pattern[i]);
        if (!v) {
            if (!set.has(arr[i])) {
                set.add(arr[i])
                map.set(pattern[i], arr[i]);
            } else {
                return false;
            }
        } else if (arr[i] !== v) {
            // console.log(false)
            return false;
        }

    }
    // console.log(true)
    return true;
};

// wordPattern('abba', 'dog cat cat dog')
// @lc code=end

